package lumis.portal.channel;

import java.util.List;



import lumis.portal.PortalException;
import lumis.portal.authentication.SessionConfig;
import lumis.portal.dao.DaoException;
import lumis.portal.manager.ManagerFactory;
import lumis.portal.stability.StableMinor;

import lumis.portal.transaction.PortalTransactionFactory;

import lumis.util.IResource;
import lumis.util.TextUtil;

/**
 * Exceptions that is raised when adding/updating a channel using a local group prefix already in use by another channel
 *
 * @version $Revision: 13082 $ $Date: 2011-05-27 16:03:12 -0300 (Fri, 27 May 2011) $
 * @since 4.0.7
 */
@SuppressWarnings("serial")
@StableMinor(version = "6.0", sinceVersion = "4.0")
public class ChannelPrefixInUseException extends DaoException
{
	private final String channelUsingPrefixId;
	private final String prefix;
	
	private static String getChannelPath(String channelUsingPrefixId) throws PortalException
	{
		return ManagerFactory.getChannelManager().getPath(SessionConfig.getCurrentSessionConfig(), channelUsingPrefixId, PortalTransactionFactory.getCurrentTransaction());
	}

	public ChannelPrefixInUseException(String channelUsingPrefixId, String prefix) throws PortalException
	{
		super("STR_CHANNEL_PREFIX_IN_USE;" + TextUtil.escapeLocalizationParameter(getChannelPath(channelUsingPrefixId)) + ";" + TextUtil.escapeLocalizationParameter(prefix));
		this.channelUsingPrefixId = channelUsingPrefixId;
		this.prefix = prefix;
	}

	public ChannelPrefixInUseException(String channelUsingPrefixId, String prefix, Exception innerException) throws PortalException
	{
		super("STR_CHANNEL_PREFIX_IN_USE;" + TextUtil.escapeLocalizationParameter(getChannelPath(channelUsingPrefixId)) + ";" + prefix, innerException);
		this.channelUsingPrefixId = channelUsingPrefixId;
		this.prefix = prefix;
	}

	public ChannelPrefixInUseException(String channelUsingPrefixId, String prefix, IResource resource) throws PortalException
	{
		super("STR_CHANNEL_PREFIX_IN_USE;" + TextUtil.escapeLocalizationParameter(getChannelPath(channelUsingPrefixId)) + ";" + prefix, resource);
		this.channelUsingPrefixId = channelUsingPrefixId;
		this.prefix = prefix;
	}

	public ChannelPrefixInUseException(String channelUsingPrefixId, String prefix, IResource resource, Exception innerException) throws PortalException
	{
		super("STR_CHANNEL_PREFIX_IN_USE;" + TextUtil.escapeLocalizationParameter(getChannelPath(channelUsingPrefixId)) + ";" + prefix, resource, innerException);
		this.channelUsingPrefixId = channelUsingPrefixId;
		this.prefix = prefix;
	}

	public ChannelPrefixInUseException(String channelUsingPrefixId, String prefix, List<IResource> resources) throws PortalException
	{
		super("STR_CHANNEL_PREFIX_IN_USE;" + TextUtil.escapeLocalizationParameter(getChannelPath(channelUsingPrefixId)) + ";" + prefix, resources);
		this.channelUsingPrefixId = channelUsingPrefixId;
		this.prefix = prefix;
	}

	public ChannelPrefixInUseException(String channelUsingPrefixId, String prefix, List<IResource> resources, Exception innerException) throws PortalException
	{
		super("STR_CHANNEL_PREFIX_IN_USE;" + TextUtil.escapeLocalizationParameter(getChannelPath(channelUsingPrefixId)) + ";" + prefix, resources, innerException);
		this.channelUsingPrefixId = channelUsingPrefixId;
		this.prefix = prefix;
	}

	public String getChannelUsingPrefixId()
	{
		return channelUsingPrefixId;
	}

	public String getPrefix()
	{
		return prefix;
	}

}
